<?php
namespace Admin\Controller;
use Think\Controller;
class LogController extends CommonController 
{
	//后台log
    public function admin_log()
    {
        //分页显示
        $admin_log = M('admin_history'); // 实例化User对象
        $count      = $admin_log->count();// 查询满足要求的总记录数
        $this->assign('num',$count);
        $Page       = new \Think\Page($count,20);// 实例化分页类 传入总记录数和每页显示的记录数(25)
        $show       = $Page->show();// 分页显示输出
        // 进行分页数据查询 注意limit方法的参数要使用Page类的属性
        $list = $admin_log->limit($Page->firstRow.','.$Page->listRows)->select();
        $this->assign('list',$list);
        $this->assign('page',$show);// 赋值分页输出

        $this->display();
    }

    //批量删除
    public function deletes()
    {
      //print_r($_POST);exit;
      //Array ( [arr] => Array ( [0] => 1 [1] => 2 ) )
      if (IS_POST) {
        $arr = I('post.arr');
        $ids = implode(",", $arr);

        //删除
        $res = M('admin_history')->delete($ids);
          if ($res) {
              $arr = array(
                  'error' =>1,
                  'info'=>"删除成功"
                  );
              echo json_encode($arr);
          }else {
              $arr = array(
                  'error' =>0,
                  'info'=>"删除失败"
                  );
              echo json_encode($arr);
          }
      }
    }   

    //彻底删除
    public function delete()
    {
      if (IS_POST) {
          $id = I('post.id');

          $sql = 'delete from admin_history where id='.$id;
          $is_del = M()->execute($sql);
          if ($is_del) {
              $arr = array(
                  'error' =>1,
                  'info'=>"彻底删除成功"
                  );
              echo json_encode($arr);
          }else {
              $arr = array(
                  'error' =>0,
                  'info'=>"彻底删除失败"
                  );
              echo json_encode($arr);
          }
      }
    }


    //前台log
    public function home_log()
    {
        //分页显示
        $home_log = M('history'); // 实例化User对象
        $count      = $home_log->count();// 查询满足要求的总记录数
        $this->assign('num',$count);
        $Page       = new \Think\Page($count,20);// 实例化分页类 传入总记录数和每页显示的记录数(25)
        $show       = $Page->show();// 分页显示输出
        // 进行分页数据查询 注意limit方法的参数要使用Page类的属性
        $list = $home_log->limit($Page->firstRow.','.$Page->listRows)->select();
        $this->assign('list',$list);
        $this->assign('page',$show);// 赋值分页输出

        $this->display();
    }
    //批量删除
    public function home_deletes()
    {
      //print_r($_POST);exit;
      //Array ( [arr] => Array ( [0] => 1 [1] => 2 ) )
      if (IS_POST) {
        $arr = I('post.arr');
        $ids = implode(",", $arr);

        //删除
        $res = M('history')->delete($ids);
          if ($res) {
              $arr = array(
                  'error' =>1,
                  'info'=>"删除成功"
                  );
              echo json_encode($arr);
          }else {
              $arr = array(
                  'error' =>0,
                  'info'=>"删除失败"
                  );
              echo json_encode($arr);
          }
      }
    }   

    //彻底删除
    public function home_delete()
    {
      if (IS_POST) {
          $id = I('post.id');

          $sql = 'delete from history where id='.$id;
          $is_del = M()->execute($sql);
          if ($is_del) {
              $arr = array(
                  'error' =>1,
                  'info'=>"彻底删除成功"
                  );
              echo json_encode($arr);
          }else {
              $arr = array(
                  'error' =>0,
                  'info'=>"彻底删除失败"
                  );
              echo json_encode($arr);
          }
      }
    }



    //底部信息管理
    public function dibu_index()
    {
      $stutags = M('stutags')->select();
      $this->assign('stutags',$stutags);

      $this->display();
    }
    //编辑显示
    public function dibu_index_edit()
    {
      $id = I('get.id');
      $stutags_one = M('stutags')->where(array('id'=>$id))->find();
      $this->assign('stutags_one',$stutags_one);

      $this->display();
    }
    //编辑
    public function dibu_index_edit_add()
    {//Array ( [id] => 1 [name] => 新闻公告x [content] => 新闻公告xxxxx )
      if (IS_POST) {
         $id = I('post.id');

         $data['name'] = I('post.name');
         $data['content'] = I('post.content');

         //入库
         $res = M('stutags')->where(array('id'=>$id))->save($data);
          if ($res) {
              $arr = array(
                  'error' =>1,
                  'info'=>"修改成功"
                  );
              echo json_encode($arr);
          }else {
              $arr = array(
                  'error' =>0,
                  'info'=>"修改失败"
                  );
              echo json_encode($arr);
          }
      }
    }

    //新闻发布 
    public function dibu_report()
    {
      $report = M('report')->select();
      $this->assign('report',$report);

      $this->display();
    }
    //添加
    public function dibu_report_add()
    {
      if (IS_POST) {
         $data['name'] = I('post.name');
         $data['content'] = I('post.content');
         $data['add_time'] = time();

         if (empty($data['name'])) {
              $arr = array(
                  'error' =>0,
                  'info'=>"标题不能为空"
                  );
              echo json_encode($arr);
              exit;
         }
         $res = M('report')->add($data);
          if ($res) {
              $arr = array(
                  'error' =>1,
                  'info'=>"添加成功"
                  );
              echo json_encode($arr);
          }else {
              $arr = array(
                  'error' =>0,
                  'info'=>"添加失败"
                  );
              echo json_encode($arr);
          }
      }else {
        $this->display();
      }
    }
    //编辑
    public function dibu_report_edit()
    {
      if (IS_POST) {
         $id = I('post.id');
         $data['name'] = I('post.name');
         $data['content'] = I('post.content');
         $data['add_time'] = time();

         if (empty($data['name'])) {
              $arr = array(
                  'error' =>0,
                  'info'=>"标题不能为空"
                  );
              echo json_encode($arr);
              exit;
         }
         $res = M('report')->where(array('id'=>$id))->save($data);
          if ($res) {
              $arr = array(
                  'error' =>1,
                  'info'=>"编辑成功"
                  );
              echo json_encode($arr);
          }else {
              $arr = array(
                  'error' =>0,
                  'info'=>"编辑失败"
                  );
              echo json_encode($arr);
          }
      }else {
        $id = I('get.id');
        $report_one = M('report')->where(array('id'=>$id))->find();
        $this->assign('report_one',$report_one);

        $this->display();
      }
    }
    //删除
    public function report_del()
    {
      if (IS_POST) {
        $id = I('post.id');
        $res = M('report')->delete($id);
        if ($res) {
            $arr = array(
                'error' =>1,
                'info'=>"删除成功"
                );
            echo json_encode($arr);
        }else {
            $arr = array(
                'error' =>0,
                'info'=>"删除失败"
                );
            echo json_encode($arr);
        }
      }
    }

    
}